/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.seguridad.modelo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Claudio
 */
@Entity
@Table(name = "sg_menu")
public class Menu implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id    
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "NOMBRE", length = 45)
    private String nombre;
    @Column(name = "ICONO", length = 80)
    private String icono;
    @Column(name = "ACCION", length = 80)
    private String accion;
    @Column(name = "URL", length = 80)
    private String url;
    @Column(name = "ACTUALIZA", length = 80)
    private String update;
    @Column(name = "ACTIVO")
    private Boolean activo;
    @Column(name = "ONCOMPLETE", length = 45)
    private String oncomplete;
    @Column(name = "NIVEL")
    private Integer nivel;
    @Column(name = "ORDEN")
    private int orden;
    @Column(name = "TIPO", length = 45)
    private int tipo;

    @JoinColumn(name = "ID_MENU", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Menu menuPrincipal;

    @OneToMany(mappedBy = "menuPrincipal")
//    @OrderColumn(name = "ORDEN")
//    @OrderBy("ORDEN ASC")
    private List<Menu> menuItem = new ArrayList<Menu>();

    @Transient
    private boolean seleccionado;


    public Menu() {
    }

    public Menu(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getIcono() {
        return icono;
    }

    public void setIcono(String icono) {
        this.icono = icono;
    }

    public String getAccion() {
        return accion;
    }

    public void setAccion(String accion) {
        this.accion = accion;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUpdate() {
        return update;
    }

    public void setUpdate(String update) {
        this.update = update;
    }

    public Boolean getActivo() {
        return activo;
    }

    public void setActivo(Boolean activo) {
        this.activo = activo;
    }

    public String getOncomplete() {
        return oncomplete;
    }

    public void setOncomplete(String oncomplete) {
        this.oncomplete = oncomplete;
    }

    public List<Menu> getMenuItem() {
        return menuItem;
    }

    public void setMenuItem(List<Menu> menuItem) {
        this.menuItem = menuItem;
    }

    public Menu getMenuPrincipal() {
        return menuPrincipal;
    }

    public void setMenuPrincipal(Menu menuPrincipal) {
        this.menuPrincipal = menuPrincipal;
    }

    public Integer getNivel() {
        return nivel;
    }

    public void setNivel(Integer nivel) {
        this.nivel = nivel;
    }

    public int getOrden() {
        return orden;
    }

    public void setOrden(int orden) {
        this.orden = orden;
    }

    public int getTipo() {
        return tipo;
    }

    public void setTipo(int tipo) {
        this.tipo = tipo;
    }


    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public boolean isSeleccionado() {
        return seleccionado;
    }

    public void setSeleccionado(boolean seleccionado) {
        this.seleccionado = seleccionado;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Menu)) {
            return false;
        }
        Menu other = (Menu) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return nombre;
    }

}
